package com.xianggu.mybatis.paging;

import java.io.Serializable;
import java.util.List;

/**
 * @author chengjy
 * @date 2025/3/12
 */
public class Page<T> implements Serializable {

    private int pageNum = 1;
    private int pageSize = 20;

    private int offset = 0;
    private int total = 0;
    private int size = 0;

    private List<T> data;

    public Page(int pageNum, int pageSize) {
        this.offset = (pageNum - 1) * pageSize;
        this.pageNum = pageNum;
        this.pageSize = pageSize;
    }

    public Page<T> setRecords(List<T> data , Integer total) {
        this.data = data;
        this.total = total;
        this.size = data.size();
        return this;
    }

    public int getPageNum() {
        return pageNum;
    }

    public int getOffset() {
        return offset;
    }

    public int getTotal() {
        return total;
    }

    public int getSize() {
        return size;
    }

    public List<T> getData() {
        return data;
    }

    public int getPageSize() {
        return pageSize;
    }

    @Override
    public String toString() {
        return "Page{" +
                "pageNum=" + pageNum +
                ", pageSize=" + pageSize +
                ", offset=" + offset +
                ", total=" + total +
                ", size=" + size +
                ", data=" + data +
                '}';
    }
}
